﻿using System;
using Model;
using Moq;
using NUnit.Framework;
using ViewsAndViewModels.Interfaces;
using ViewsAndViewModels.ViewModels;

namespace UnitTests
{
    [TestFixture]
    public class ViewModelValidation
    {
        private const string PasswordReturnValue = "abcdefgh";
        private Mock<IPasswordGenerator> _generatorMock;
        private Mock<IMainContentView> _viewMock;
        private void CreateMocks()
        {
            _generatorMock = new Mock<IPasswordGenerator>();
            _viewMock = new Mock<IMainContentView>();
        }
        [Test]
        public void DefaultInitializeBehaviour()
        {
            CreateMocks();
            _generatorMock.Setup(q => q.GeneratePassword(It.IsAny<PasswordGenerationInfo>())).Returns(PasswordReturnValue);
            var vm = new MainContentViewModel(_viewMock.Object, _generatorMock.Object);
            Assert.IsTrue(String.CompareOrdinal(vm.ComputedPassword, PasswordReturnValue) == 0);
        }
        [Test]
        public void CommandPatternValidatorNegative()
        {
            CreateMocks();
            _generatorMock.Setup(q => q.GeneratePassword(It.IsAny<PasswordGenerationInfo>())).Returns(PasswordReturnValue);
            var vm = new MainContentViewModel(_viewMock.Object, _generatorMock.Object)
                {
                    IsLeftHandChecked = false,
                    IsRightHandChecked = false
                };
            Assert.IsFalse(vm.CopyToClipboardCommand.CanExecute());
            Assert.IsFalse(vm.SaveToFileCommand.CanExecute());
            Assert.IsFalse(vm.RegenerateCommand.CanExecute());
        }
        [Test]
        public void CommandPatternValidatorPositive()
        {
            CreateMocks();
            _generatorMock.Setup(q => q.GeneratePassword(It.IsAny<PasswordGenerationInfo>())).Returns(PasswordReturnValue);
            var vm = new MainContentViewModel(_viewMock.Object, _generatorMock.Object)
            {
                IsLeftHandChecked = false,
                IsRightHandChecked = true
            };
            Assert.IsTrue(vm.CopyToClipboardCommand.CanExecute());
            Assert.IsTrue(vm.SaveToFileCommand.CanExecute());
            Assert.IsTrue(vm.RegenerateCommand.CanExecute());
            vm = new MainContentViewModel(_viewMock.Object, _generatorMock.Object)
            {
                IsLeftHandChecked = true,
                IsRightHandChecked = false
            };
            Assert.IsTrue(vm.CopyToClipboardCommand.CanExecute());
            Assert.IsTrue(vm.SaveToFileCommand.CanExecute());
            Assert.IsTrue(vm.RegenerateCommand.CanExecute());
        }
    }
}
